from fastapi import HTTPException
from typing import Optional

class BusinessError(HTTPException):
    def __init__(self, detail: str, status_code: int = 400):
        super().__init__(status_code=status_code, detail=detail)

class ResourceNotFoundError(BusinessError):
    def __init__(self, resource_name: str, resource_id: Optional[str] = None):
        detail = f"{resource_name} not found"
        if resource_id:
            detail = f"{resource_name} with id {resource_id} not found"
        super().__init__(detail=detail, status_code=404)

class DuplicateResourceError(BusinessError):
    def __init__(self, resource_name: str, field: str, value: str):
        super().__init__(
            detail=f"{resource_name} with {field} '{value}' already exists",
            status_code=400
        )
